import Toast from "@vant/weapp/dist/toast/toast";
import { getToken } from "@/utils/auth";

/**
 * 关于前端代码运行环境的判断，比如是微信还是普通浏览器，是手机还是电脑,是安卓还是iphone
 */
const ua =
  typeof window === "object"
    ? window.navigator && window.navigator.userAgent
    : "";

const _isIOS = -1;
let _isAndroid = -1;
/**
 *是ios
 * @returns {Boolean} res true表示是ios，android表示是安卓
 */

/**
 * 是安卓
 * @returns
 */
export function isAndroidFn() {
  if (_isAndroid === -1) _isAndroid = /Android/i.test(ua) ? 1 : 0;
  return _isAndroid === 1;
}
/**
 *
 * @returns 是否是IOS
 */
export const getIsIos = ({ fn }) => {
  wx.getSystemInfo().then((res) => {
    let result = false;
    console.log("平台", res.platform);

    if (res.platform == "ios") {
      result = true;
    }
    // result = true;
    fn(result);
    return result;
  });
};
/**
 * 当前是否是在电脑里
 * @returns
 */
function isComputed() {
  if (!document) {
    return false;
  }
  const html = document.documentElement;
  const clientWidth = html.clientWidth;
  return clientWidth >= 1024;
}

export const isAndroid = isAndroidFn();
export const isCompute = isComputed(); // 是电脑就返回true，否则返回false
export const isWeixin = function () {
  return /MicroMessenger/i.test(navigator && navigator.userAgent);
};
let reg = new RegExp(/dev|test|localhost/g);
export const isTest = reg.test(uni.getStorageSync("siteInfo").siteDomain);
